package com.order.controller.seller;

import com.baomidou.mybatisplus.extension.api.R;
import com.github.pagehelper.PageInfo;
import com.order.pojo.ProductCategory;
import com.order.service.ProductCategoryService;
import com.order.utils.Result;
import com.sun.org.apache.regexp.internal.RE;
import io.swagger.annotations.*;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Update;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.rmi.CORBA.Util;
import java.util.List;

@Api(tags = "餐饮类别接口")
@RestController
@Slf4j//输出语句
@ApiResponses({
        @ApiResponse(code = 200, message = "新增成功", response = ProductCategory.class),
        @ApiResponse(code = 400, message = "参数错误"),
        @ApiResponse(code = 403, message = "权限被禁止"),
        @ApiResponse(code = 500, message = "服务器内部错误")
})
@RequestMapping("/seller/ProductCategory")
public class ProductCategoryController {
    @Autowired
    ProductCategoryService productCategoryService;

    @GetMapping("/list")
    public Result findAll() {
        log.info("日志输出");
        return Result.success(productCategoryService.findAll());
    }

    @GetMapping("selectPage")
    public Result selectPage( ProductCategory productCategory,
                             @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                             @RequestParam(value = "pageSize", defaultValue = "2") int pageSize) {
        PageInfo<ProductCategory> pageInfo=productCategoryService.selectpage(pageNum,pageSize,productCategory);
        return Result.success(pageInfo);
    }

    @ApiOperation("根据ID查询餐饮类别")
    @GetMapping("/list/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId", value = "列表ID"),
    })
    public Result getById(@PathVariable("id") Integer categoryId) {
        return Result.success(productCategoryService.getById(categoryId));
    }

    @ApiOperation("新增餐饮类别")
    @PostMapping("/save")
    public Result save(@RequestBody ProductCategory productCategory) {
        return Result.success(productCategoryService.save(productCategory));
    }

    @ApiOperation("修改餐饮类别")
    @PutMapping("/update")
    public Result update(@RequestBody ProductCategory productCategory) {
        productCategory.getUpdateTime();
        return Result.success(productCategoryService.updateById(productCategory));
    }

    @ApiOperation("删除餐饮类别")
    @DeleteMapping("delete/{id}")
    public Result delete(@PathVariable("id") Integer categoryId) {
        ProductCategory productCategory=new ProductCategory(categoryId,1);
        return Result.success(productCategoryService.updateById(productCategory));
    }
}
